package com.higold.cloud.mvp.presenter

import com.higold.cloud.base.BasePresenter
import com.higold.cloud.mvp.contract.RegionalDetailContract
import com.higold.cloud.mvp.model.RegionalDetailModel
import com.higold.cloud.net.exception.ExceptionHandle

/**
 *    author : lxz
 *    date   : 2019/9/3 10:53
 *    desc   :
 */
class RegionalDetailPresenter : BasePresenter<RegionalDetailContract.View>(), RegionalDetailContract.Presenter {

    private val regionalDetailModel by lazy { RegionalDetailModel() }

    override fun requestRegionalDetail(salemanId : String) {
        checkViewAttached()
        mRootView?.showLoading()
        val disposable = regionalDetailModel.requestRegionalDetail(salemanId)
                .subscribe({ regionalDetail ->
                    mRootView?.setRegionalList(regionalDetail)
                }, { throwable ->
                    //处理异常
                    mRootView?.showError(ExceptionHandle.handleException(throwable), ExceptionHandle.errorCode)
                })
        addSubscription(disposable)
    }
}